#ifndef __GUI_H__
#define __GUI_H__
#include "types.h"
#include "error.h"
#include "maps.h"
#include "model.h"
#include "graphcut.h"
#include <stdlib.h>
#include <sstream>
#include <algorithm>
#include <assert.h>

#include <QMainWindow>
#include <QImage>
#include <QLabel>
#include <QtGui>
#include <qfiledialog.h>
#include <QGroupBox>
#include <QPushButton>

class QSlider;

class MainWindow;
class FormArea : public QWidget {
	Q_OBJECT
private:
	QSlider 				*edgeslider,
									*pcslider;
	QPushButton 		*processButton,
									*resetButton;
	QRadioButton		*radioMarkRect,
									*radioMarkDraw,
									*radioHeatmapProb,
									*radioHeatmapSeg;
public:
	void updateMarkerView(bool b);
	FormArea(QWidget *parent = 0);
	int getEdgeSliderValue() const;
	int getPcSliderValue() const;
	void reset();
public slots:
};
class RenderArea : public QLabel{ ///*}
	Q_OBJECT

public:
	void setTop(MainWindow *top);
	RenderArea();
public slots:
protected:
	void mousePressEvent(QMouseEvent *event);
	void mouseReleaseEvent(QMouseEvent *event);
	void mouseMoveEvent(QMouseEvent *event);
	void mousePaint(int x, int y);
private:
	int rescaleX(int x) const;
	int rescaleY(int y) const;
	int rescale(int v, float f) const;
	void drawRectangle(int x1, int y1, int x2, int y2);
	MainWindow *_qoTop;
	bool _bLMB;
	bool _bRMB;
	QSize _qoMouseDown;
};//*/

class QAction;
class QActionGroup;
class QLabel;
class QMenu;
class QScrollArea;

class MainWindow : public QMainWindow {
	Q_OBJECT

public:
	MainWindow();
	void setTrimapPoint(int x, int y,Trimap::obu v);
	QSize getImageSize();
	QImage getTargetImage();
	bool getMarkerMode();
	bool hasChanged() const;
	void changed();
	bool isInitialised() const;
	void initialised();

protected:
public slots:
	void reset();
	void process();
private slots:
	void open();
	void saveSeg();
	void saveTri();

	void changeMode(bool);
	void changeMode();
	void changeHeatmap(bool);

	void about();

#ifdef DEBUG
	void loglvl();
	void chgModel();
#endif

private:
	void createActions();
	void createMenus();

	void initialiseFile(QString qsFileName);
	void displayImage();
	void displayHeatmap();

	bool	_bMarkerMode,
				_bChanged,
				_bInitialised,
				_bShowHeatmap;
	QImage _qoSourceImage;
	QImage _qoTargetImage;
	Trimap _oTrimap;
	Model *_oModel;
	Multimap	_oSegmentation,
						_oProbs;

	QMenu *fileMenu;
	QMenu *editMenu;
	QMenu *helpMenu;
#ifdef DEBUG
	QMenu *debugMenu;
#endif

	QAction *openAct;
	QAction *saveSegAct;
	QAction *saveTriAct;
	QAction *exitAct;

	QAction *resetAct;
	QAction *changeModeAct;
	QAction *processAct;

	QAction *aboutAct;

#ifdef DEBUG
	QAction *loglvlAct;
	QAction *chgModelAct;
#endif

	RenderArea	*renderArea;
	QLabel	*heatmapArea;
	QLabel	*objectonlyArea;
//	QLabel *renderArea;
	FormArea	*formArea;
};

#endif
